<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'Locations' );

$locations = get_locations();
?>
					<div class="blok">
<?php
print_operations_tab( 'Locations' );
?>
					</div>
					<br />
<?php
if( count( $locations ) > 0 ) {
?>
					<table>
						<th colspan="4">
							<?php transprint( 'Locations' ); ?>
						</th>
						<tr>
							<td><?php transprint( 'Title' ); ?></td>
							<td><?php transprint( 'Location' ); ?></td>
							<td><?php transprint( 'Share with faction' ); ?></td>
							<td><?php transprint( 'Remove' ); ?></td>
						</tr>
<?php
	$count = 0;
	foreach( $locations AS $location ) {
?>
						<tr class="<?php ( $count % 2 == 0 ) ? print( 'even' ) : print( 'odd' ); ?>">
							<td>
								<form method="post" action="set_location_title.php">
									<input type="hidden" name="location_id" value="<?php print( $location->location_id ); ?>" />
									<input type="text" size="15" name="title" value="<?php print( $location->title ); ?>" />
									<input type="submit" value="<?php transprint( 'set' ); ?>" />
								</form>
							</td>
							<td>
								<?php print( get_location_link( $location ) ); ?>
							</td>
							<td>
								<form method="post" action="set_location_share.php">
									<input type="hidden" name="location_id" value="<?php print( $location->location_id ); ?>" />
									<select name="share" onchange="this.parentNode.submit();">
										<option value="share"<?php ( $location->share == 1 ) ? print( ' selected="selected"' ) : print( '' ); ?>><?php transprint( 'share' ); ?></option>
										<option value="no_share"<?php ( $location->share == 0 ) ? print( ' selected="selected"' ) : print( '' ); ?>><?php transprint( 'don\'t share' ); ?></option>
									</select>
								</form>
							</td>
							<td>
								<form method="post" action="delete_location.php">
									<input type="hidden" name="location_id" value="<?php print( $location->location_id ); ?>" />
									<input type="submit" value="<?php transprint( 'remove' ); ?>" />
								</form>
							</td>
						</tr>
<?php		
		$count ++;
	}
?>
					</table>
<?php	
}
else {
?>
					<div class="blok">
						<?php transprint( 'You don\'t have any locations stored at the moment.' ); ?>
					</div>
<?php	
}

$shared_locations = get_shared_locations();
if( count( $shared_locations ) > 0 ) {
?>
					<br />
					<table>
						<th colspan="2">
							<?php transprint( 'Shared locations' ); ?>
						</th>
						<tr>
							<td><?php transprint( 'Location' ); ?></td>
							<td><?php transprint( 'Shared by' ); ?></td>
						</tr>
<?php
	$count = 0;
	foreach( $shared_locations AS $location ) {
		$query2 = "SELECT name " .
				"FROM ruler " .
				"WHERE ruler_id = " . $location->ruler_id;
		$result2 = mysql_query( $query2 ) or die("Query failed : " . mysql_error());
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC);
		$ruler_link = '<a href="../overview/ruler.php?name=' . $row2[ 'name' ] . '"><strong class="blue">' . $row2[ 'name' ] . '</strong></a>'
?>
						<tr class="<?php ( $count % 2 == 0 ) ? print( 'even' ) : print( 'odd' ); ?>">
							<td>
								<?php print( get_location_link( $location ) ); ?>
							</td>
							<td>
								<?php print( $ruler_link ); ?>
							</td>
						</tr>
<?php
		$count ++;
	}
?>
					</table>
<?php	
}
aos_footer();
?>